﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Web;
using jSLApp.Web.Workflow;
using jSLCore.Service.Security;
using jSLCore.Service.Workflow;
using Telerik.Windows;

namespace jSLApp.Web
{
    /// <summary>
    /// Для закачки фильмов
    /// </summary>
    public class FilmUploadHandler : RadUploadHandler
    {
        public override string GetTargetFolder()
        {
            return MainService.MoviesFolder;
        }

        public override string GetFileName()
        {
            var fileName = (string)Context.Session["FileName"];

            if (fileName==null)
            {
                fileName = Guid.NewGuid() + ".wmv";
                Context.Session.Add("FileName", fileName);
            }
            return fileName;
        }
        
        public override Dictionary<string, object> GetAssociatedData()
        {
            var associatedData = base.GetAssociatedData();
            if (IsFinalFileRequest())
            {
                Context.Session.Remove("FileNameResult");
                associatedData.Add("FileNameResult", GetFileName());
            }
            return associatedData;
        }
    }
}